package com.minelx.statementplus.ui.form.service.tablemapping;

import com.alibaba.fastjson.JSONObject;

import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

public class CompositeTableMapping implements ITableMapping {
	private final List<ITableMapping> mappings;

	public CompositeTableMapping(List<ITableMapping> mappings) {
		this.mappings = mappings;
	}

	@Override
	public JSONObject customSql() {
		JSONObject result = new JSONObject();
		for (ITableMapping mapping : mappings) {
			result.putAll(mapping.customSql());
		}
		return result;
	}

	@Override
	public Set<String> fieldTables() {
		return mappings.stream().map(ITableMapping::fieldTables)
				.flatMap(Collection::stream)
				.collect(Collectors.toSet());
	}
}
